<template>
	<view class="container pad-32">
		<u-navbar placeholder title="充值" :autoBack="true"></u-navbar>
		<u--form class="pad-top-30" labelPosition="left" :model="info" ref="form1" labelWidth="180rpx"
			:labelStyle="{fontSize: '28rpx'}">
			<view class="bg-white pad-left-right-24 pad-top-bottom-16 radius24">
				<u-form-item label="充值金额" prop="tel" :borderBottom="false">
					<u--input type="number" clearable placeholderClass="input-style" placeholder="请输入充值的金额"
						v-model="info.amount" border="none"></u--input>
				</u-form-item>
			</view>
		</u--form>

		<u-button :customStyle="{borderRadius: '12rpx'}" class="mar-top-96 font-32 button bg-theme"
			@click="submit">充值</u-button>
	</view>
</template>

<script>
	// 接口地址
	import {
		addRechargeOrder,
		cashierPay
	} from '@/config/api.js'
	import {
		llWallet
	} from '@/config/url.js'
	export default {
		data() {
			return {
				info: {
					amount: ''
				},
			}
		},
		onLoad(options) {},
		methods: {
			// 判断环境
			getEnvironment() {
				// #ifdef APP-PLUS
				return 'app'
				// #endif

				// #ifdef H5
				return 'wap'
				// #endif
			},
			// 确定重置
			submit() {
				if (this.info.amount == '') {
					uni.showToast({
						title: '请输入充值的金额',
						icon: 'none'
					})
					return
				}

				addRechargeOrder({
					plat_id: 11,
					amount: this.info.amount
				}).then(order => {
					// 支付订单
					cashierPay({
						order_id: order.data.order_id,
						pay_plat: 11,
						os: this.getEnvironment()
					}).then(res => {
						uni.hideLoading();

						let {
							pay_data
						} = res.data;
						// #ifdef APP-PLUS
						let url =
							`https://h5.xuenuo8.cn/llPay.html?url=${encodeURIComponent(pay_data.pay_url)}`
						plus.runtime.openURL(url)
						// #endif
						// #ifdef H5
						window.location.href = pay_data.pay_url
						// #endif

					})
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.button {
		box-shadow: 0 10px 15px rgba(223, 0, 7, .1);
		height: 96rpx;
		color: white;
	}

	.input-style {
		color: rgb(192, 196, 204) !important;
	}


	.container {
		box-sizing: border-box;
		background: url('../../static/image/my-bg.png') no-repeat;
		background-size: 100% 100%;
		height: 100vh;


		::v-deep .u-navbar__content {
			background-image: url('../../static/image/my-bg.png');
			background-size: cover;
			background-repeat: no-repeat;
		}
	}
</style>